package com.shopping.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.shopping.model.Goods;
import com.shopping.model.Tops;
import com.shopping.model.Users;
import com.shopping.service.IGoodsService;
import com.shopping.service.ITopsService;

@Controller
@RequestMapping("/index")
public class IndexController {

	@Autowired
	private IGoodsService goodsService;
	
	@Autowired
	private ITopsService topsService;
	
	/**
	 * 主页显示
	 * @param topsCur
	 * @param model
	 * @return
	 */
	@RequestMapping("/findTopsByPage")
	public String findTopsByPage(Integer topsCur,Model model) {
		int page = 1;
		int pageSize = 10;
		if(topsCur!=null) {
			page = topsCur;
		}
		int offset = (page-1)*pageSize;
		List<Tops> tops = topsService.findByPage(offset, pageSize);
		List<Goods> todayList = new ArrayList<Goods>();
		//获取推荐中对应的商品信息
		for (Tops top : tops) {
			todayList.add(goodsService.findById(top.getGoodId()));
		}
		//查询热销商品
		List<Goods> hotList = goodsService.findByPage(0, 8);
		
		//产品分类
		
		//存入今日推荐
		model.addAttribute("todayList", todayList);
		//存入热销排行
		model.addAttribute("hotList", hotList);
		return "index.jsp";
	}
}
